home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 42 / Amiga Format AFCD42 (Issue 126, Aug 1999).iso / -serious- / misc / cedbar / splitguide.g < prev    next >
Text File  |  1999-05-17  |  4KB  |  172 lines

  1. G4C
  2.  
  3. WINBIG 155 73 338 94 'Split a guide into nodes'
  4. wintype 11110001
  5. resinfo 8 660 270
  6. box 0 0 0 0 out button
  7.  
  8. ; =======================================================
  9. ;       on load / close
  10. ; =======================================================
  11.  
  12. xonload
  13. setgad splitguide.g 1/2 hide  ; hide lvs
  14. dirname = "Ram:"
  15. guiopen splitguide.g
  16.  
  17. xonclose
  18. guiquit splitguide.g
  19.  
  20. ; =======================================================
  21. ;       guide name gadget
  22. ; =======================================================
  23.  
  24. CTEXT 14 4 "Enter name of guide to be split:" #screen 8 2 0 0001
  25.  
  26. XTEXTIN 10 16 290 14 "" guidename "" 100
  27. gadid 10
  28. setgad splitguide.g 11 on
  29.  
  30. XBUTTON 301 16 25 14 "<"
  31. ReqFile -1 -1 300 -30 "Choose a Guide:" LOAD guidename ''
  32. update splitguide.g 10 $guidename
  33.  
  34. ; =======================================================
  35. ;       dir name gadget
  36. ; =======================================================
  37.  
  38. CTEXT 12 32 "Enter name of dir to put nodes in:" #screen 8 2 0 0001
  39.  
  40. XTEXTIN 10 44 290 14 "" dirname "Ram:" 100
  41. gadid 11
  42.  
  43. XBUTTON 302 44 25 14 "<"
  44. ReqFile -1 -1 300 -30 "Choose or Create a Directory:" DIR dirname ''
  45. update splitguide.g 11 $dirname
  46.  
  47.  
  48. ; =======================================================
  49. ;       status 
  50. ; =======================================================
  51.  
  52. CTEXT 11 62 "Status:" #screen 8 2 0 0001
  53.  
  54. TEXT 10 74 238 14 "Idle." 40 BOX
  55. gadid 12
  56.  
  57. ; =======================================================
  58. ;       listviews for data handling
  59. ; =======================================================
  60.  
  61. XLISTVIEW 0 0 343 72 '' lv1 '' 0 MULTI
  62. gadid 1
  63. XLISTVIEW 0 0 343 72 '' lv2 '' 0 MULTI
  64. gadid 2
  65.  
  66. ; =======================================================
  67. ;       The routine that does the actual spliting
  68. ; =======================================================
  69.  
  70. XBUTTON 254 74 74 14 "Split!"
  71. local t
  72.  
  73.    if $guidename < ' '
  74.    or $dirname < ' '
  75.       ezreq 'Incorrect parameters!' OK ''
  76.       stop
  77.    endif
  78.  
  79.    ifexists dir '~$dirname'
  80.       makedir '$dirname'
  81.    endif
  82.  
  83.    update splitguide.g 12 "Loading guide.."
  84.    lvuse splitguide.g 1
  85.    lvchange $guidename
  86.    olddir = $$g4c.dir
  87.    cd $dirname
  88.  
  89.    ; find 1st node
  90.    gosub splitguide.g gonext @NODE FIRST
  91.    nodeline = $$lv.line
  92.    if $nodeline = ''
  93.       return
  94.    endif
  95.  
  96.    ; goto after the @database & get & save headers
  97.    update splitguide.g 12 "Processing Header.."
  98.    lvgo #1
  99.    t = $($nodeline - 2)
  100.    if $t > 0
  101.       lvclip cut $($nodeline - 2) paste splitguide.g 2
  102.       lvuse splitguide.g 2
  103.       lvsave CBAG_Header
  104.    endif
  105.  
  106.    ; find 1st node again..
  107.    gosub splitguide.g gonext @NODE FIRST
  108.    nodeline = $$lv.line
  109.  
  110.    while $nodeline > ''
  111.  
  112.       ; get name
  113.       ln = $$lv.rec
  114.       cutvar ln cut word 2 ln
  115.       cutvar ln cut word -1 ln
  116.       extract ln unquote ln
  117.       update splitguide.g 12 "Processing node $ln"
  118.       
  119.       lvgo next
  120.       ++nodeline
  121.       
  122.       gosub splitguide.g gonext @ENDNODE NEXT
  123.       if $$lv.line == ''
  124.          ezreq "ERROR:\nNode: $ln\nNo @EndNode!\n" OK ''
  125.          update splitguide.g 12 "Aborted."
  126.          cd $olddir
  127.          stop   
  128.       endif
  129.       nodeend = $($$lv.line - 1)
  130.       lvgo #$nodeline
  131.       lvclip cut $($nodeend - $nodeline) paste splitguide.g 2
  132.       
  133.       lvuse splitguide.g 2
  134.       lvsave $ln
  135.  
  136.       ; find next node..
  137.       gosub splitguide.g gonext @NODE NEXT
  138.       nodeline = $$lv.line
  139.  
  140.    endwhile
  141.  
  142.    update splitguide.g 12 "Finished."
  143.    cd $olddir
  144.  
  145. ; =======================================================
  146. ;     routine to find the next @command
  147. ;    txt  = either @NODE or @ENDNODE
  148. ;    smod = either FIRST or NEXT
  149. ; =======================================================
  150.  
  151.  
  152. xROUTINE gonext txt smod
  153.  
  154.    lvuse splitguide.g 1
  155.    if $smod == FIRST
  156.       lvsearch $txt ci first
  157.    else
  158.       lvsearch $txt ci next
  159.    endif
  160.  
  161.    while $$search.pos != 0    ; check that it's the 1st word
  162.    and $$lv.line > ''
  163.       lvsearch $txt ci next
  164.    endwhile
  165.  
  166.  
  167.  
  168.  
  169.  
  170.  
  171.  
  172.